// Copyright 2022 jeff.li. and/or its affiliates.

#include <gtest/gtest.h>
#include <cfloat>

#include <tbir/runtime/builtins_modules/_floatobject.h>

namespace tbir::runtime {

    TEST(PythonBuiltins, floatobject_float_rem) {
        EXPECT_EQ(py_builtins::float_rem(5.0, 3.0), 2.0);
        EXPECT_EQ(py_builtins::float_rem(5.0, -3.0), -1.0);
        EXPECT_EQ(py_builtins::float_rem(-5.0, 3.0), 1.0);
        EXPECT_EQ(py_builtins::float_rem(-5.0, -3.0), -2.0);
    }

    TEST(PythonBuiltins, floatobject_float_floor_div) {
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(5.1, 3.2), 1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(5.1, -3.2), -2.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-5.1, 3.2), -2.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-5.1, -3.2), 1.0);

        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.1, 3.2), 0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.1, -3.2), -1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.1, 0.1), 1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.1, -0.1), -1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-0.1, 3.2), -1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-0.1, -3.2), -0.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-0.1, 0.1), -1.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(-0.1, -0.1), 1.0);

        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.0, 3.2), 0.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.0, -3.2), -0.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.0, 0.1), 0.0);
        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(0.0, -0.1), -0.0);

        EXPECT_DOUBLE_EQ(py_builtins::float_floor_div(double(INT64_MAX), double(INT64_MAX)), 1.0);
    }

}  // namespace tbir::runtime
